www.gusucode.com > C++ 游戏类库源码程序 > C++ 游戏类库源码程序\code\游戏类库\game_地图.cpp
/* [学VC、编游戏] 编著、程序设计:唐明理 2004.7 E-mail: cqtml@163.com */ #include "stdafx.h" #include "game_地图.h" extern unsigned short dw[7][6]; gamemap:: gamemap(){} gamemap::~gamemap() {DeleteObject(pen1); } void gamemap::initmap() { mapt=10,mapb=120; maph=mapb-mapt; mapl=WIDTH+6; mapr=mapl+maph*WIDTH/HEIGHT; mapw=mapr-mapl; hScrDC=CreateDC("DISPLAY", NULL, NULL, NULL); SMAP =CreateCompatibleDC(hScrDC); mapbit=CreateCompatibleBitmap(hScrDC,mapw,maph); SelectObject(SMAP,mapbit); pen0.CreatePen(PS_SOLID,1,RGB(0x0,0xf0,0xf0)); pen1.CreatePen(PS_SOLID,1,RGB(0x60,0x60,0x60)); DeleteDC(hScrDC); fls=0; movemap=0; init(); } void gamemap::exitmap() { DeleteDC(BK); DeleteObject(bi); DeleteObject(mapbit); DeleteDC(SMAP); DeleteObject(pen0); exit(); } void gamemap::mlmap() { if( movemap==0) BitBlt(BkDC1,0,0,WIDTH,HEIGHT,BkDC0,0,0,SRCCOPY); else {int gx=scrx%WIDTH,gy=scry%HEIGHT; BitBlt(BK, 0,0, WIDTH-gx,HEIGHT,BkDC0,gx,0,SRCCOPY); BitBlt(BK, WIDTH-gx, 0,gx,HEIGHT, BkDC0,0,0, SRCCOPY); BitBlt(BkDC1,0,0, WIDTH,HEIGHT-gy,BK,0,gy, SRCCOPY); BitBlt(BkDC1,0,HEIGHT-gy,WIDTH,gy, BK,0,0, SRCCOPY); } sort(); movemap=0; } void gamemap::getsmap() { char name[256]; sprintf(name,"%s%s",dir,mapbak); loadbmp(name); SelectObject(BkDC0,bitmap);// DeleteObject(bitmap); int i,j; COLORREF col=RGB(255,255,255); for(i=0;i<mapw;i=i+mapw/SCRP0) for(j=0;j<maph;j=j+maph/SCRP0) TransparentBlt2 (SMAP,i,j,mapw/SCRP0,maph/SCRP0, BkDC0,0,0,WIDTH,HEIGHT,col); int wi=WIDTH*SCRP0,he=HEIGHT*SCRP0; for(int q=0;q<rs;q++) if(man[q].lb==2) {if(getpic("景",man[q].p)==FALSE) continue; int x=(man[q].xix-w/4)*mapw; int y=(man[q].xiy-h)*maph; TransparentBlt2 (SMAP,x/wi,y/he,(w*mapw)/(wi*2/3),(h*maph)/(he*2/3), MemDC,0,0,w,h,col); } } void gamemap::movesmap(int x0,int y0) { int a=3; if(edi==1) a=1; if(x0>SCRWI-10) {scrx=scrx+GX/a;if(scrx>WIDTH*(SCRP0-1)) scrx=WIDTH*(SCRP0-1);} if(x0<10) {scrx=scrx-GX/a;if(scrx<0) scrx=0;} if(y0>SCRHE-10) {scry=scry+GY/a;if(scry>HEIGHT*(SCRP0-1)) scry=HEIGHT*(SCRP0-1);} if(y0<10) {scry=scry-GY/a;if(scry<0) scry=0;} movemap=1; } BOOL gamemap::dingweimap(int x,int y) { if(y>mapt&&y<mapb&&x>mapl&&x<mapr) {scrx=(x-mapl)*WIDTH *SCRP0/mapw-mapw*2; scry=(y-mapt)*HEIGHT*SCRP0/maph-maph*2; scrx=(scrx/GX)*GX; scry=(scry/GY)*GY; if(scrx>WIDTH*(SCRP0-1)) scrx=WIDTH*(SCRP0-1); if(scrx<0) scrx=0; if(scry>HEIGHT*(SCRP0-1)) scry=HEIGHT*(SCRP0-1); if(scry<0) scry=0; return TRUE; } return FALSE; } void gamemap::smlmap(HDC dc0) { if(rs<1||SCRP0<1) return; CDC* dc = CDC::FromHandle (dc0); BitBlt(dc0,mapl,mapt,mapw,maph,SMAP,0,0,SRCCOPY); CPen *old; old=dc->SelectObject(&pen0); int mapw0=mapw/SCRP0,maph0=maph/SCRP0-1; int scrx0=mapl+(scrx*mapw)/(WIDTH*SCRP0); int scry0=mapt+(scry*maph)/(HEIGHT*SCRP0); dc->MoveTo(scrx0,scry0); dc->LineTo(scrx0+mapw0,scry0); dc->LineTo(scrx0+mapw0,scry0+maph0); dc->LineTo(scrx0,scry0+maph0); dc->LineTo(scrx0,scry0); for(int q=0;q<rs;q++) { COLORREF col=RGB(0x0,0x0,0x0); scrx0=(man[q].xix*mapw)/(WIDTH*SCRP0)-1; scry0=(man[q].xiy*maph)/(HEIGHT*SCRP0)-2; if(scrx0<1||scry0<1) continue; if(man[q].jisu==0) {mann=q; if(fls==0){fls=1;col=RGB(0xf0,0xf0,0xf0);} else {fls=0;col=RGB(0xf0,0x0,0x0);} dc->SetPixel(mapl+scrx0+1,mapt+scry0, col); dc->SetPixel(mapl+scrx0+1,mapt+scry0+1,col); } if(man[q].lb==2) continue; dc->SetPixel(mapl+scrx0,mapt+scry0, col); dc->SetPixel(mapl+scrx0,mapt+scry0+1,col); } setfind(dc,old); dc->SelectObject(old); CDC::DeleteTempMap( ); } int gamemap::leftdown(HDC hdc,int x,int y) { int fidtim=0; if(x>0&&x<WIDTH&&y>0&&y<HEIGHT&&edi==0) {int i=mann; man[i].x0=x-2+scrx; man[i].y0=y-10+scry; man[i].p=man[i].m1-1; } if(dingweimap(x,y)==TRUE) smlmap(hdc); return fidtim; } void gamemap::setfind(CDC* dc,CPen *old) { int i=mann; dc->SelectObject(old); if(man[i].pk<1) { CDC::DeleteTempMap( ); return; } int x,y,x0,y0; x=man[i].ph[0].x*GX; y=man[i].ph[0].y*GY; x0=mapl+(x*mapw)/(WIDTH*SCRP0); y0=mapt+(y*maph)/(HEIGHT*SCRP0); old=dc->SelectObject(&pen1); for (int j=1;j<man[i].pk;j++) {dc->MoveTo(x0,y0); x=man[i].ph[j].x*GX; y=man[i].ph[j].y*GY; x0=mapl+(x*mapw)/(WIDTH*SCRP0); y0=mapt+(y*maph)/(HEIGHT*SCRP0); dc->LineTo(x0,y0); } x0=mapl+(man[i].fx*mapw)/(WIDTH*SCRP0); y0=mapt+(man[i].fy*maph)/(HEIGHT*SCRP0); dc->LineTo(x0,y0); }